let person = { 
    name:'冯总', 
    age:18, 
    like: {
        sport: 'running',
        food: 'beef'
}} 


function deepCopy(obj) {
    // let obj1 = obj instanceof Array ? [] : {}
    // for(let p in obj) {
    //     if(obj[p] instanceof Object) {
    //       obj1[p] = deepCopy(obj[p])
    //     } else{
    //         if(obj.hasOwnProPerty(p)) {
    //             obj1[p] = obj[p] 
    //         }
    //     }
    // }
    // return obj1
    let copy = obj instanceof Array ? [] : {}
    for(let i in obj) {
        if(obj.hasOwnProperty(i)) {
            copy[i] = obj[i] instanceof Object ? deepCopy(obj[i]) : obj[i]
        }
    }
    return copy
}

let deepPerson = deepCopy(person)
person.like.sport = 'swimming'

console.log(deepPerson); 